﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Management;

namespace Twi.COMMON.HTTP
{
    /// <summary>
    /// 静态常量
    /// </summary>
    public class ConstClass
    {
        //#region  判断窗体或控件是否为设计模式
        ///// <summary>
        ///// 判断窗体或控件是否为设计模式
        ///// </summary>
        //public static bool IsInDesignMode
        //{
        //    get
        //    {
        //        return (bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue;
        //    }
        //}
        //#endregion

        
        #region IP地址
        /// <summary>
        /// IP地址
        /// </summary>
        private static string _ip = "";
        /// <summary>
        /// IP地址
        /// </summary>
        public static string IP
        {
            get
            {
                if (_ip.Length < 1)
                {
                    ///获取本地的IP地址            

                    foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                    {
                        if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
                        {
                            _ip = _IPAddress.ToString();
                            break;
                        }
                    }
                }
                return ConstClass._ip;
            }
            set { ConstClass._ip = value; }
        }
        #endregion

        #region MAC地址
        /// <summary>
        /// MAC地址
        /// </summary>
        private static string _macAddress = string.Empty;
        /// <summary>
        /// MAC地址
        /// </summary>
        public static string MACAddress
        {
            get
            {
                if (_macAddress.Length < 1)
                {
                    ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
                    ManagementObjectCollection queryCollection = query.Get();
                    foreach (ManagementObject mo in queryCollection)
                    {
                        if (mo["IPEnabled"].ToString() == "True")
                            _macAddress = mo["MacAddress"].ToString();
                    }
                }
                return ConstClass._macAddress;
            }
            set { ConstClass._macAddress = value; }
        }
        #endregion

        #region 操作名称
        /// <summary>
        /// 操作名称
        /// </summary>
        private static string _operateName = string.Empty;
        /// <summary>
        /// 操作名称
        /// </summary>
        public static string OperateName
        {
            get { return _operateName; }
            set { _operateName = value; }
        }
        #endregion
    }
}

